#include "Calculator.hpp" // 业务 // 应用层
#include "Parser.hpp" // 报文解析，序列反序列化等 // 表示层
#include "TcpServer.hpp" // 网络通信开断连接 //会话层
//#include "Daemon.hpp"
#include <memory>

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " localport" << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }

    //Daemon();

    EnableConsoleLogStrategy();
    //EnableFileLogStrategy();

    // 计算机对象
    std::unique_ptr<Calculator> cal = std::make_unique<Calculator>();

    // 协议解析的模块
    std::unique_ptr<Parser> parser = std::make_unique<Parser>([&cal](Requst &req)->Response{
        return cal->Exec(req);
    });

    // 网络通信模块
    uint16_t serverport = std::stoi(argv[1]);
    std::unique_ptr<TcpServer> tsock = std::make_unique<TcpServer>(
        serverport, [&parser](std::string &inbuffer)->std::string{
            return parser->Parse(inbuffer);
    });

    tsock->Run();


    return 0;
}